-- bine_addon
-- create by panyl
-- 魔藤加成属性技能

return {
    apply = function(source, target, skillId, round, para, extra)
        assert(target.type == OBJECT_TYPE_BINE, "魔藤加成属性技能");

        local attribValue;
        if para[2] == "max_hp" then
            attribValue = target:getMaxHp();
        elseif para[2] == "max_mp" then
            attribValue = target:getMaxMp();
        elseif para[2] == "attack" then
            attribValue = target:getAttack();
        elseif para[2] == "magic" then
            attribValue = target:getMagic();
        end

        local v = extraCeil(attribValue * para[3], 1000);
        -- local v = math.ceil(attribValue * para[3] / 1000);
        local prop = { para[1], para[2], v, -1, };
        PropM.record(target, prop, "skill");

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tostring(arr[2]), tonumber(arr[3]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        local bine = source;
        if (source.type == OBJECT_TYPE_USER) then
            bine = source.bine;
        end

        local addHp = extraCeil(bine:getMaxHp() * para[3], 1000);
        local addMp = extraCeil(bine:getMaxMp() * para[3], 1000);
        -- local addHp = math.ceil(bine:getMaxHp() * para[3] / 1000);
        -- local addMp = math.ceil(bine:getMaxMp() * para[3] / 1000);
        local addAttack = extraCeil(bine:getAttack() * para[3], 1000);
        local addMagic  = extraCeil(bine:getMagic() * para[3], 1000);
        -- local addAttack = math.ceil(bine:getAttack() * para[3] / 1000);
        -- local addMagic  = math.ceil(bine:getMagic() * para[3] / 1000);

        desc = string.gsub(desc, "{bine_addon}", para[3] / 10);

        desc = string.gsub(desc, "{max_hp}", addHp);

        desc = string.gsub(desc, "{max_mp}", addMp);

        desc = string.gsub(desc, "{attack}", addAttack);

        desc = string.gsub(desc, "{magic}", addMagic);

        return desc;
    end,
};
